Skip to content

feat(pgxpool): acquire ping timeout#2393

Merged
jackc merged 2 commits into
jackc:masterfrom
amirsalarsafaei:ping-timeout
Oct 13, 2025
Merged

feat(pgxpool): acquire ping timeout#2393
jackc merged 2 commits into
jackc:masterfrom
amirsalarsafaei:ping-timeout

Conversation

@amirsalarsafaei

Copy link
Copy Markdown
Contributor

this commit adds ping timeout in acquire loop for when the connection ping results in timeout instead of an error

@amirsalarsafaei

Copy link
Copy Markdown
Contributor Author

@jackc the PR is final could you please review this.

@amirsalarsafaei amirsalarsafaei force-pushed the ping-timeout branch 3 times, most recently from ef422db to 76d013d Compare October 6, 2025 11:55
this commit adds ping timeout in acquire loop for when the connection ping results in timeout instead of an error
@jackc

jackc commented Oct 11, 2025

Copy link
Copy Markdown
Owner

The code looks reasonable but it seems the test is flickering.

@amirsalarsafaei amirsalarsafaei force-pushed the ping-timeout branch 4 times, most recently from 6e7a097 to 436656d Compare October 12, 2025 08:30
@amirsalarsafaei

Copy link
Copy Markdown
Contributor Author

@jackc thanks for the review, I think I fixed the flickering, I added a proxy interface simulating real delay (using sleep) to ensure PingTimeout never flickers.

@jackc jackc merged commit cf86575 into jackc:master Oct 13, 2025
26 of 28 checks passed
@jackc

jackc commented Oct 13, 2025

Copy link
Copy Markdown
Owner

Thanks!

Comment thread pgxpool/pool.go
if p.pingTimeout > 0 {
var cancel context.CancelFunc
pingCtx, cancel = context.WithTimeout(ctx, p.pingTimeout)
defer cancel()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this defer inside for loop can accumulate unnecessary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it will be better if handled at the end of the loop, but I don't think it has an overhead does it? Just the order of executions changes. The defer struct without any arguments is very lightweight as I remember

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants